﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="newsbabylist.aspx.cs" Inherits="UI.system.page.news.newsbabylist" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ Import Namespace="Model" %>
<%@ Import Namespace="DAL" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/system/js/jquery.min.js"></script>
    <script src="/system/layui/layui.js"></script>
    <script src="/system/layui/lay/modules/laydate.js"></script>
    <script src="/system/js/common.js"></script>
    <script src="/system/js/md5.js"></script>
    <script src="/js/swfupload.js"></script>
    <link rel="stylesheet" href="/system/layui/css/layui.css">
    <link rel="stylesheet" href="/system/css/iframe.css">
    <link rel="stylesheet" href="/system/css/viewer.css">
    <script src="/system/js/viewer.js"></script>
    <script src="/js/clipboard.min.js"></script>
    <style>
        td img{height:40px; float:left;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="layer-toolbar layui-form">
        <div class="layer-toolbar-left">
            <div style="position:absolute; left:-1000px; top:-1000px;"><input type="radio" name="radio"  value="" title="" /></div>
        </div>
        <div class="layer-toolbar-right">
            <div class="layui-input-inline lefts" style="width:120px; margin-right:5px;">
            <select id="type" name="type" lay-filter="type">
                <option value="-1">全部</option>
                <option value="1">现金红包活动</option>
                <option value="2">免费领奖活动</option>
            </select>
            </div>
            <div class="layui-input-inline lefts" style="width:100px; margin-right:5px;">
            <select id="state" name="state" lay-filter="state">
                <option value="-1">全部</option>
                <option value="1">投放中</option>
                <option value="2">已暂停</option>
                <option value="3">已结束</option>
            </select>
            </div>
            <input id="begindate" type="text" name="title" placeholder="开始时间" autocomplete="off" class="layui-input" value="" style="width:100px;" onclick="layui.laydate({elem: this, format: 'YYYY-MM-DD'})"><div class="texts">-</div>
            <input id="enddate" type="text" name="title" placeholder="结束时间" autocomplete="off" class="layui-input" value="" style="width:100px;" onclick="layui.laydate({elem: this, format: 'YYYY-MM-DD'})">
            <input id="keyword" type="text" name="title" placeholder="活动名称" autocomplete="off" class="layui-input" value="" style="width:150px;" onkeyup='CRM.Enter("#search")'>
            <a id="search" class="layui-btn layui-btn-small layui-btn-normal" onclick="Search()">搜索</a>
            <a class="layui-btn layui-btn-small" onclick="Search()">刷新</a>
        </div>
    </div>
    <div id="iframe" class="layer-iframe">
    <div class="layui-form">
    <table class="layui-table">
    <colgroup>
      <col width="80">
      <col width="80">
      <col width="100">
      <col width="88">
      <col>
      <col width="88">
      <col width="60">
      <col width="60">
      <col width="60">
      <col width="60">
      <col width="60">
      <col width="88">
      <col width="100">
      <col width="88">
      <col width="100">
      <col width="80">
      <col width="80">
      <col width="90">
      <col width="110">
      <col width="60">
    </colgroup>
    <thead>
      <tr>
        <th>发布人</th>
        <th>关键词</th>
        <th>活动名称</th>
        <th>活动图片</th>
        <th>活动内容</th>
        <th>红包类型</th>
        <th>红包个数</th>
        <th>红包金额</th>
        <th>已领个数</th>
        <th>已领金额</th>
        <th>剩余个数</th>
        <th>领奖方式</th>
        <th>省市区</th>
        <th>活动距离</th>
        <th>地址</th>
        <th>状态</th>
        <th>点击量</th>
        <th>分享次数</th>
        <th>创建时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody id="layer-table">
        <tr><td colspan="20" class="center">数据加载中...</td></tr>
    </tbody>
     <script id="data-table" type="text/html">
      {{#  layui.each(d, function(index, item){ }}
      <tr>
        <td>{{item.NickName}}</td>
        <td>{{item.Keyword}}</td>
        <%if(B.MyAdmin.Role==1){ %>
        <td><a onclick="Show_PrizeRecord({{item.ID}})">{{item.Name}}</a></td>
        <%}else{ %>
        <td>{{item.Name}}</td>
        <%} %>
        <td><img src="{{item.Img}}" width="50"/></td>
        <%if(B.MyAdmin.Role==1){ %>
        <td><a class="copy" data-clipboard-text="http://www.kdxny84.cn/activess.aspx?id={{item.IDPwd}}" target="_blank">{{item.Context.Cut(30)}}</a></td>
        <%}else{ %>
        <td>{{item.Context.Cut(30)}}</td>
        <%} %>
        <td>{{item.MoneyType==1?"随机红包":"指定红包"}}</td>
        <td>{{item.Count}}</td>
        <td>{{item.AllMoney}}</td>
        <td>{{item.TakeCount}}</td>
        <td>{{item.TakeMoney}}</td>
        <%if(B.MyAdmin.Role==1){ %>
        <td><a onclick="Update_TakeCount({{item.ID}},{{item.Count-item.TakeCount}})">{{item.Count-item.TakeCount<0?0:item.Count-item.TakeCount}}</a></td>
        <%}else{ %>
        <td>{{item.Count-item.TakeCount<0?0:item.Count-item.TakeCount}}</td>
        <%} %>
        <td>{{item.PrizeTypeText}}</td>
        <td>{{item.Province}}-{{item.City}}-{{item.Area}}</td>
        <td>{{item.Metre}}</td>
        <td>{{item.Address}}</td>
        <td>{{item.StateText}}</td>
        <td>{{item.ClickCount}}</td>
        <td>{{item.ShareCount}}</td>
        <td>{{item.CreateDate}}</td>
        <td style="line-height:30px;">
        <%if(B.MyAdmin.Role==1){ %>
        <a class="layui-btn layui-btn-mini" onclick="Set_ActiveKeyword({{item.ID}})" style="margin-bottom:3px;">关键词</a>
        <a class="layui-btn layui-btn-mini" onclick="StateSet_Active({{item.ID}})" style="margin-bottom:3px;">状态</a>
        <a class="layui-btn layui-btn-mini" onclick="IsAutoSet_Active({{item.ID}})" style="margin-bottom:3px;">自动</a>
        <a class="layui-btn layui-btn-mini" onclick="Down_Img({{item.ID}})" style="margin-bottom:3px;">一键兼容</a>
        <a class="layui-btn layui-btn-mini" onclick="Save_Active({{item.ID}})" style="margin-bottom:3px;">编辑</a>
        <a class="layui-btn layui-btn-mini layui-btn-danger" onclick="Delete_Active(this,{{item.ID}})">删除</a>
        <%} %>
        </td>
      </tr>
      {{#  }); }}
      </script>
    </table>
    </div>
    </div>
    <div id="layer-page" class="layer-page"></div>
    </form>
    <script>
        layui.use(['form', 'laytpl', 'element'], function () {
            $ = layui.jquery, form = layui.form(), laytpl = layui.laytpl;
            Init_Pager(1);
            form.on("select(state)", function (data) {
                Search();
            });
            form.on("select(type)", function (data) {
                Search();
            });
        });

        function Init_Pager(pageindex) {
            var data = {};
            data.act = "Find_Active";
            data.pageindex = pageindex;
            data.begindate = $("#begindate").val();
            data.enddate = $("#enddate").val();
            data.keyword = $("#keyword").val();
            data.state = $("#state").val();
            data.type = $("#type").val();
            data.flag = 1;
            data.sign = GetSign(data.act);
            Loading();
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
                var json = $.parseJSON(r);
                if (json.state) {
                    Pager(json.data.list, json.data.count);
                }
                else {
                    LayerBox.Error(json.msg);
                }
            });
        };


        function Save_Admin(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/admin/adminadd.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title + "", html, 630, 400, null, function (form) {
                    var data = form;
                    data.act = "Save_Admin";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    data.power = ""; // CRM.ListValue(".checkbox input:checked");
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };



        function Delete_Active(o, id) {
            LayerBox.Confirm("您确定要删除吗？", function () {
                Delete_Table(o, id, "Delete_Active");
            });
        };


        function StateSet_Active(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/active/stateset.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("修改状态", html, 450, 180, null, function (form) {
                    var data = form;
                    data.act = "StateSet_Active";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });

            });
        };
        function IsAutoSet_Active(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/active/isautoset.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("修改发放方式", html, 450, 180, null, function (form) {
                    var data = form;
                    data.act = "IsAutoSet_Active";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });

            });
        };
        function Save_Active(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/active/activeadd.aspx?id=" + id, function (html) {
                LayerBox.Close.ByAll();
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title + "活动", html, 590, 710, null, function (form) {
                    var data = form;
                    data.act = "Save_Active";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    data.img = window.parent.$(".img_container img").attr("src");
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
                var upload = new window.parent.Upload_File("upload_img");
                upload.swfu.handle = "upload_active";
            });
        };

        function Show_PrizeRecord(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/active/recordlist.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Detail("领奖人", html, 980, 580, null, function (form) {
                });
            });
        };

        function Update_TakeCount(id, leavecount) {
            LayerBox.Loading();
            Ajax.Get("/system/page/active/updatetakecount.aspx?id=" + id + "&leavecount=" + leavecount, function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("扣除数量", html, 390, 290, null, function (form) {
                    var data = form;
                    data.act = "Update_TakeCount";
                    data.id = id;
                    data.leavecount = leavecount;
                    if (data.increasecount > leavecount) {
                        LayerBox.Error("扣除数量不能大于剩余数量");
                        return;
                    }
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg);
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };

        function Set_ActiveKeyword(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/active/setkeyword.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("关键词", html, 380, 280, null, function (form) {
                    var data = form;
                    data.act = "Set_ActiveKeyword";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };

        function Down_Img(id) {
            LayerBox.Confirm("您确定要执行该操作吗？", function () {
                var data = {};
                data.act = "Down_Img";
                data.id = id;
                data.sign = GetSign(data.act);
                LayerBox.Loading();
                Ajax.Post("/tools/Admin.ashx", data, function (r) {
                    LayerBox.Close.ByAll();
                    var json = $.parseJSON(r);
                    if (json.state) {
                        LayerBox.Success(json.msg, 500, function () {
                            if (id == 0) {
                                $(".layui-laypage").remove();
                                Init_Pager(1);
                            } else {
                                var currpage = 1;
                                if ($(".layui-laypage-curr em").length > 0) {
                                    currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                }
                                Init_Pager(currpage);
                            }
                        });
                    }
                    else {
                        LayerBox.Error(json.msg);
                    }
                });
            });
        };

        var clipboard = new Clipboard(".copy"); //实例化
        clipboard.on('success', function (e) {
            LayerBox.Success("复制成功");
        });
</script>
</body>
</html>